TSQL: Converting/Casting String between Unicode and Non-Unicode

Categories: Database; Tagged with: ; @ January 16th, 2013 12:04

I got an Error in a SSIS package:

 cannot convert between unicode and non-unicode string data types.

We can use one component called ‘DataConversion’, but I think directly convert the type in SQL will be better.

SQL:

DECLARE @str_unicode NVARCHAR(32);
SET @str_unicode = NCHAR(9734);
SELECT @str_unicode

— Using CAST
SELECT CAST(@str_unicode AS VARCHAR(32))

— Using Convert
SELECT CONVERT(VARCHAR(32), @str_unicode)

Result:

image

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.